package com.itheima.bufferedreaderstream;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;

public class Test {

    public static void main(String[] args) {

        //缓冲字符输入流读取字符内容：性能提升，且多了按行读取的方法

        try (
                //1.创建文件字符输入流对象与文件接通
                Reader reader = new FileReader("io\\src\\poem.txt");
                //2.创建缓冲字符输入流对象包装低级的字符输入流对象
                BufferedReader br = new BufferedReader(reader);
        ) {

            /*char[] chars = new char[1024];
            int len;
            while ((len = br.read(chars)) != -1) {
                String str = new String(chars, 0, len);
                System.out.print(str);
                //System.out.println(new String(chars, 0, len));
            }*/

            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            //目前读取文本最佳的读取方式：按行读取


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
